package com.think.teaching.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.think.teaching.mapper.PaperZoneMapper;
import com.think.teaching.model.PaperZone;
import com.think.teaching.service.PaperZoneService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 试卷分区 服务实现类
 * </p>
 *
 * @author think
 * @since 2020-08-12
 */
@Service
public class PaperZoneServiceImpl extends BaseServiceImpl<PaperZoneMapper, PaperZone> implements PaperZoneService {

	@Override
	public PaperZone AddPaperZone(PaperZone paperZone) {
		if (this.save(paperZone)) {
			return paperZone;
		}
		return null;
	}

	@Override
	public PaperZone UpdatePaperZone(PaperZone paperZone) {
		if (this.updateById(paperZone)) {
			return paperZone;
		}
		return null;
	}

	@Override
	public PaperZone GetPaperZone(Integer id) {
		QueryWrapper<PaperZone> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("id", id).eq("state", 1).ne("delflag", 1);
		return getOne(queryWrapper);
	}

	@Override
	public PaperZone SetPaperZoneState(Integer id, Integer state) {
		UpdateWrapper<PaperZone> queryWrapper = new UpdateWrapper<>();
		queryWrapper.eq("id", id).ne("delflag", 1).set("state", state);
		this.update(queryWrapper);
		return getById(id);
	}

}
